package org.example.qqrobot.controller.user;

import lombok.extern.slf4j.Slf4j;
import org.example.qqrobot.model.Result;
import org.example.qqrobot.model.dto.InvitationLikeDTO;
import org.example.qqrobot.model.dto.InvitationNewDTO;
import org.example.qqrobot.model.dto.InvitationQueryDTO;
import org.example.qqrobot.model.pojo.Invitation;
import org.example.qqrobot.model.vo.InvitationIntoPageVO;
import org.example.qqrobot.model.vo.InvitationMainVO;
import org.example.qqrobot.service.InvitationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/invitation")
@Slf4j
public class InvitationController {
    @Autowired
    private InvitationService invitationService;


    @PostMapping("/getList")
    public Result getList(@RequestBody InvitationQueryDTO invitationQueryDTO){
        log.info("查询相关的帖子，{}",invitationQueryDTO);

        List<InvitationMainVO> iList = invitationService.query(invitationQueryDTO);

        return Result.success(iList);


    }

    @GetMapping("intoPage")
    public Result intoPage(Long id){
        log.info("进入帖子详情，{}",id);

        InvitationIntoPageVO invitationIntoPageVO = invitationService.intoPage(id);

        return Result.success(invitationIntoPageVO);
    }

    @PostMapping("/save")
    public Result save(@RequestParam("title") String title,@RequestParam("content") String content,@RequestParam("image") String image){
        log.info("发一个帖子，{},{},{}",title,content,image);

        invitationService.save(title,content,image);

        return Result.success(1);

    }

    @PostMapping("/like")
    public Result like(@RequestParam("invitationId") Long invitationId,@RequestParam("yourId") Long yourId){
        log.info("给帖子点赞，{},{}",invitationId,yourId);
        invitationService.like(invitationId,yourId);
        return Result.success(1);
    }

    @PostMapping("/search")
    public Result search(@RequestParam("queryName") String queryName){
        log.info("搜索帖子信息，{}",queryName);
        List<InvitationMainVO> invitationMainVOList = invitationService.queryByName(queryName);
        if(invitationMainVOList.size() == 0){
            return Result.success();
        }
        return Result.success(invitationMainVOList);
    }
}
